'use strict';
var Model = require('../../../Base/server/controllers/Model'),
    CBOEnum = require('../../../CBO/server/controllers/Enum.server.controller.js');

var modelField = {};
modelField.Code = {
    type: String,
    Name: '编码',
    IsUnique: true,
    IsEmpty: false,
    trim: true
};
modelField.Name = {
    type: String,
    Name: '名称',
    IsEmpty: false,
    trim: true
};

//唯一标识
modelField.UniqueID = {
    type: String,
    trim: true,
    Name: '唯一标识',
    IsEmpty: false
};

modelField.IsEffective = {
    type: Boolean
};

//设备类型 0: Pad 1：读头 2：其他
modelField.Type = {
    type: Number,
    Name: '设备类型',
    IsEmpty: false
};

//来源类型
modelField.SourceType = {
    type: Number,
    Name: '来源类型',
    Enum: CBOEnum.TerminalSourceType,
    IsEmpty: true
};

modelField.LastRequestDate = {
    type: Date
};

modelField.Remark = {
    type: String,
    Name: '备注',
    default: '',
    trim: true
};

var newModel = new Model(modelField);
newModel.addIndex({Code: 1});
newModel.addIndex({UniqueID: 1});
var newEntity = newModel.create('Terminal', '终端设备');

newEntity.OnValidate = function(){
    if(this.Type == null || this.Type == undefined || this.Type < 0){
        throw new Error("请录入设备类型");
    }
}
